@tool
extends Area2D

const TEXTURE_BY_TYPE = {
	"right" = Color.WHITE,
	"worse" = Color.WHITE
}

enum TYPE{
	RIGHT,
	WORSE,
}

@export_multiline var text:String
@export var type: TYPE
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var label: Label = $Label

func _ready() -> void:
	if not Engine.is_editor_hint():
		var randtexture = randi_range(0,3)
		label.text = text
		body_entered.connect(on_body_entered)
		if type == TYPE.WORSE:
			animated_sprite_2d.modulate = TEXTURE_BY_TYPE.get("worse")
		else:
			animated_sprite_2d.modulate = TEXTURE_BY_TYPE.get("right")


func _process(delta: float) -> void:
	if Engine.is_editor_hint():
		label.text = text
		if type == TYPE.WORSE:
			animated_sprite_2d.modulate = TEXTURE_BY_TYPE.get("worse")
		else:
			animated_sprite_2d.modulate = TEXTURE_BY_TYPE.get("right")
		if Engine.get_process_frames() % 10 == 0:
			var frame = randi_range(0,3)
			animated_sprite_2d.frame = frame
	else:
		if Engine.get_process_frames() % 10 == 0:
			var frame = randi_range(0,3)
			animated_sprite_2d.frame = frame


func on_body_entered(body: Character) -> void:
	MusicPlayer.play_sfx("Delusion")
	if type == TYPE.WORSE:
		body.die()
	queue_free()
